package com.firefly.web.controller.api.user;

import com.firefly.web.controller.api.ApiRestController;
import com.firefly.dao.dto.mc.McUserUpdateNickDto;
import com.firefly.dao.vo.mc.McUserVo;
import com.firefly.service.command.mc.McUserCommand;
import com.firefly.service.query.mc.McUserQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 用户管理
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/2/10
 **/
@ApiRestController("user")
public class McUserController {
    private final McUserCommand mcUserCommand;
    private final McUserQuery mcUserQuery;
    @Autowired
    public McUserController(McUserCommand mcUserCommand,McUserQuery mcUserQuery){
        this.mcUserCommand = mcUserCommand;
        this.mcUserQuery = mcUserQuery;
    }
    // 获取用户信息
    @GetMapping("detail")
    public McUserVo getDetail(HttpServletRequest request){
        return mcUserQuery.getDetail(Integer.valueOf(request.getParameter("requestUserId")));
    }

    // 更新头像昵称
    @PostMapping("nickname")
    public Boolean postNickname(@Validated McUserUpdateNickDto request){
        return mcUserCommand.updateNickThumb(request);
    }

    // 退出
    @PostMapping("logout")
    public Boolean postLogout(HttpServletRequest request){
        return mcUserCommand.logout(request.getParameter("requestUserId"));
    }
}
